package com.jingan.nursinghome.regulatory.dialog;

import android.graphics.Color;
import android.os.Build;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;

import com.jingan.nursinghome.regulatory.R;
import com.jingan.nursinghome.regulatory.view.WheelTurns2;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import cn.android.support.v7.lib.sin.crown.base.BaseActivity;
import cn.android.support.v7.lib.sin.crown.base.BaseApplication;
import cn.android.support.v7.lib.sin.crown.base.BaseDialog;
import cn.android.support.v7.lib.sin.crown.base.BaseListenner;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/9/22.
 */

public class ScoreDialog extends BaseDialog {
    private static ScoreDialog dateDialog;

    private int cSore;//默认选中分数
    private int maxScore;

    //Integer.valueOf("009")会自动转换成9
    //DateDialog.getInstance(this,Integer.valueOf(UtilTime.getInstance().getAbsoluteTime("yyyy")),Integer.valueOf(UtilTime.getInstance().getAbsoluteTime("MM")),Integer.valueOf(UtilTime.getInstance().getAbsoluteTime("dd")));
    //回調返回list數組，年，月，日
    public static ScoreDialog getInstance(BaseActivity activity, int sore,int maxScore, BaseListenner<Integer> baseListenner) {
//        Log.e("test","传递分数:\t"+sore+"\t最大分数：\t"+maxScore);
        if (isFinishing(dateDialog)) {
            dateDialog = new ScoreDialog(activity);
            dateDialog.cSore = sore;
            dateDialog.maxScore=maxScore;
            dateDialog.baseListenner = baseListenner;
        } else {
            dateDialog.cSore = sore;
            dateDialog.maxScore=maxScore;
            dateDialog.baseListenner = baseListenner;
            dateDialog.show();
        }
        return dateDialog;
    }

    public ScoreDialog(BaseActivity activity) {
        init(activity, R.layout.dialog_score, true, false);
        window.setWindowAnimations(R.style.Crown_Window_bottom);
        //BaseApplication.getInstance().setStatusBarDrak(window, true);
        init();
        adapter();
    }

    BaseListenner<Integer> baseListenner;

    @Override
    protected void listener() {

        findViewById(R.id.crown_date_dialog_bg).setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                    dismiss();
                }
                return true;
            }
        });

        buttonComplete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (baseListenner != null) {
                    List<Integer> list = new ArrayList<Integer>();
                    baseListenner.onResult(score.curentValue);
                }
                dismiss();
            }
        });

        initData();

    }

    @Override
    protected void recycleView() {

    }

    Button buttonComplete;
    WheelTurns2 score;

    private void init() {
        buttonComplete = (Button) findViewById(R.id.crown_btn_complete);
        score = (WheelTurns2) findViewById(R.id.score);

    }

    int width, height, count;

    private void initData() {
        List<Integer> scores = new ArrayList<>();
        for (int i = 0; i <= maxScore; i++) {
            scores.add(i);
        }
        width = findViewById(R.id.crown_date_dialog).getLayoutParams().width;
        height = ProportionUtils.getInstance().adapterInt(360);
        count = 5;
        score.setData(dateDialog.cSore,scores, "分", width, height, count);

    }

    private void adapter() {
        ProportionUtils.getInstance().adapterScreen(baseActivity, findViewById(R.id.crown_date_dialog));
        ProportionUtils.getInstance().adapterView(findViewById(R.id.crown_startLine));
        ProportionUtils.getInstance().adapterView(findViewById(R.id.crown_endLine));
        ProportionUtils.getInstance().adapterButton(buttonComplete);
        ProportionUtils.getInstance().adapterButton((Button) findViewById(R.id.btn_info));
    }
}
